package project3.association;

import java.util.Arrays;

/**
 * Represents an item set.
 */
public final class ItemSet {

	private final double[] items;
	
	private int support;
	
	public int getSupport() {
		return support;
	}

	public void setSupport(int support) {
		this.support = support;
	}

	public ItemSet(int length) {
		this.items = new double[length];
		Arrays.fill(this.items, -1D);
		
	}
	
	ItemSet(double[] items) {
		this.items = items.clone();
	}

	@Override
	public int hashCode() {
		return Arrays.hashCode(this.items);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (null == obj) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		if (false == obj instanceof ItemSet) {
			return false;
		}
		ItemSet other = (ItemSet) obj;
		return Arrays.equals(this.items, other.items);
	}

	public void setValue(int index, double value) {
		this.items[index] = value;
	}

	public int size() {
		int size = 0;
		for (int i = 0; i < this.items.length; i++) {
			if (this.items[i] != -1) {
				size++;
			}
		}
		return size;
	}

	public double getValueAt(int index) {
		return this.items[index];
	}

	@Override
	public String toString() {
		return "ItemSet [items=" + Arrays.toString(items) + ", support="
				+ support + "]";
	}

	public double[] getRawValues() {
		return this.items.clone();
	}
	
	

}
